package com.asiainfo.iov.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.asiainfo.iov.configs.ConstantsME;
import com.framework.security.RSAmethodInAssets;
import com.framework.utils.ActivityTaskUtil;
import com.framework.utils.PreferencesHelper;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 用来解决透明主题bug的闪屏页
 *
 * @author YobertJomi
 * className SplashActivity
 * created at  2017/4/27  10:03
 */
public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityTaskUtil.getInstance().addActivity(this);
        Executors.newScheduledThreadPool(1).schedule(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finish();
            }
        }, 2000, TimeUnit.MILLISECONDS);

        if (!TextUtils.isEmpty(RSAmethodInAssets.rsaDecrypt(this, PreferencesHelper.getInstance().getStringData
                (ConstantsME
                        .PHONE)))
                && !TextUtils.isEmpty(PreferencesHelper.getInstance().getStringData(ConstantsME.token))
                && PreferencesHelper.getInstance().getBooleanData(ConstantsME.LOGINED)
                && !TextUtils.isEmpty(PreferencesHelper.getInstance().getStringData(ConstantsME.currentShopId))) {

            startActivity(new Intent(SplashActivity.this, HomepageActivity.class));
        } else {
            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
        }
//        setContentView(R.layout.activity_splash);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityTaskUtil.getInstance().removeActivity(this);
    }
}
